"""
Case Type   : 系统内部使用工具
Case Name   : dsscmd工具读取磁阵文件内容之-D DSS_HOME参数验证
Create At   : 2024/2/6
Owner       : songjing20
Description :
    1.读取磁阵文件内容，指定-D $DSS_HOME参数
Expect      :
    1.报错
History     :
"""

import os
import unittest

from yat.test import Node
from yat.test import macro
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger


class SystemInternalTools(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f"----- {os.path.basename(__file__)} start -----")
        self.constant = Constant()
        self.node_pri = Node('PrimaryDbUser')

    def test_gs_backup(self):
        text = '-----step1:读取磁阵文件内容，指定-D $DSS_HOME参数;expect:报错-----'
        self.log.info(text)
        self.log.info('-----获取磁阵文件 -----')
        cmd = f"source {macro.DB_ENV_PATH};" \
              f"cat {macro.DSS_INSTANCE}/cfg/dss_vg_conf.ini"
        self.log.info(cmd)
        res = self.node_pri.sh(cmd).result()
        self.log.info(res)
        cmd = f'''source {macro.DB_ENV_PATH};
        dsscmd dev -p {res.splitlines()[0].split(':')[-1].strip()} \
-o 2048 -f c -D {macro.DSS_INSTANCE}'''
        self.log.info(cmd)
        dsscmd_res = self.node_pri.sh(cmd).result()
        self.log.info(dsscmd_res)
        self.assertIn('input -D hit no args.', dsscmd_res, f"执行失败:{text}")

    def tearDown(self):
        self.log.info(f"----- {os.path.basename(__file__)} end -----")
